package org.geektimes.projects.user.web.controller;

import com.sun.javafx.binding.StringFormatter;
import javafx.beans.binding.StringExpression;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.geektimes.configuration.microprofile.DefaultConfigProviderResolver;
import org.geektimes.web.mvc.controller.PageController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.logging.Logger;

/**
 * @Author: jipeng
 * @Description:
 * @Date: Created in 2021/3/22 7:09
 */
@Path("/config")
public class ConfigController implements PageController {
    private final Logger logger = Logger.getLogger(this.getClass().getName());


    @GET
    @POST
    @Path("/info")
    public String configInfo(HttpServletRequest request, HttpServletResponse response) {

        ConfigProviderResolver configProviderResolver = DefaultConfigProviderResolver.instance();
        Config config = configProviderResolver.getConfig();

        String applicationName = config.getValue("application.name", String.class);
        Integer port = config.getValue("application.port", Integer.class);
        String strValue = String.format("=============== Application Name  %s =============== ", applicationName);
        logger.info(strValue);
        strValue = String.format("=============== Application Port  %s =============== ", port);
        logger.info(strValue);

        return "index.jsp";
    }
}
